using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Project
{
    public partial class CurrencyConverter : System.Web.UI.Page
    {
        //protected HtmlGenericControl Result;
        //protected HtmlInputButton Convert;
        //protected HtmlInputText US;
        protected void Page_Load(object sender, EventArgs e)
        {
            Result.InnerText = "results here";
            if (this.IsPostBack == false)
            {
                //Currency.Items.Add("Euro");
                //Currency.Items.Add("Jap Yen");
                //Currency.Items.Add("Can Dol");

                // key, value pair
                Currency.Items.Add(new ListItem("Euro", "1.12"));
                Currency.Items.Add(new ListItem("Jap Yen", "122.33"));
                Currency.Items.Add(new ListItem("Can Dol", "1.48"));
            }
        }

        // This method runs automatically when an instance of this class is created.
        protected override void OnInit(EventArgs e)
        {
            // Call the custom procedure for connecting event handlers.
            InitializeComponent();

            // Call the base implementation of Page.OnInit(), just in case there's 
            // important code there.
            base.OnInit(e);
        }

        private void InitializeComponent() { 
            // Connect all event handlers.
            Convert.ServerClick += new EventHandler(Convert_ServerClick);
        }

        protected void Convert_ServerClick(Object sender, EventArgs e)
        {
            //decimal USAmount = decimal.Parse(US.Value);
            //decimal euroAmount = USAmount * 1.12M;
            //Result.InnerText = USAmount.ToString() + " US dollars = ";
            //Result.InnerText += euroAmount.ToString() + " Euros.";

            decimal amount = Decimal.Parse(US.Value);

            // get select ListItem object by its index number
            ListItem item = Currency.Items[Currency.SelectedIndex];

            decimal newAmount = amount * Decimal.Parse(item.Value);
            Result.InnerText = amount.ToString() + "US dollars = ";
            Result.InnerText += newAmount.ToString() + " " + item.Text;
            

        }
    }
}
